<?php 
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Match</title>
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/bootstrap-datepicker3.css" rel="stylesheet" />
<link href="Content/site.css" rel="stylesheet" />
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/bootstrap.js"></script>
<script src="Scripts/bootstrap-datepicker.js"></script>
<?php $scheduleID=$_GET['id'];?>
<?php include_once("php/match_classes.php");?>
</head>
<body>
<div class="container blue_border">
<?php 
include_once("php/banner.php");
?>
<?php 
include_once("php/nav_bar.php");
?>
<div class="row well text-center bgF3F5FC">
  <?php include("php/match_variables.php");?>
  <h2> <?php echo "Round ".$round->round_number." (".$round->round_date.")";?></h2>
  <h3><?php echo $team1->team_name;?> vs <?php echo $team2->team_name;?></h3>
  <h3>
  	<?php $winLostTeamMatches=$repCalc->countTeamWonMatches($scheduleID);
			if ( $winLostTeamMatches['winTeam1']>$winLostTeamMatches['winTeam2'])
			echo "<span class='score-win'>";
			else 
			echo "<span class='score-loose'>";
			echo $winLostTeamMatches['winTeam1']."</span>"?>
            &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;
			<?php 
			if ( $winLostTeamMatches['winTeam2']>$winLostTeamMatches['winTeam1'])
			echo "<span class='score-win'>";
			else 
			echo "<span class='score-loose'>";
			echo $winLostTeamMatches['winTeam2']."</span>";?>&nbsp;
  </h3>
</div>
<div class="row">
<div class="container-fluid">
  <div class="row">
    <div class="col-md-10 col-xs-12 col-md-offset-1">
      <table class="table table-striped table-bordered align-center">
        <thead>
          <tr>
            <th><?php echo $team1->team_name;?></th>
            <th>Won</th>
            <th>Lost</th>
            <th></th>
            <th><?php echo $team2->team_name;?></th>
            <th>Won</th>
            <th>Lost</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="align-left"><?php $player=$repPlayer->map($repPlayer->readPlayer($players1[0])); echo $player->fname." ".$player->sname; ?></td>
            <td>
            <?php $winLostMatches=$repCalc->countWonMatches($scheduleID,$player->playerID); 
			echo $winLostMatches['win'];?>
            </td>
            <td><?php echo $winLostMatches['lost']; ?> </td>
            <td rowspan="3" class="vs-inner">VS</td>
            <td class="align-left"><?php $player=$repPlayer->map($repPlayer->readPlayer($players2[0])); echo $player->fname." ".$player->sname; ?></td>
             <td>
            <?php $winLostMatches=$repCalc->countWonMatches($scheduleID,$player->playerID); 
			echo $winLostMatches['win'];?>
            </td>
            <td><?php echo $winLostMatches['lost']; ?> </td>
            
          </tr>
          <tr>
            <td class="align-left"><?php $player=$repPlayer->map($repPlayer->readPlayer($players1[1])); echo $player->fname." ".$player->sname; ?></td>
             <td>
            <?php $winLostMatches=$repCalc->countWonMatches($scheduleID,$player->playerID); 
			echo $winLostMatches['win'];?>
            </td>
            <td><?php echo $winLostMatches['lost']; ?> </td>
            
            <td class="align-left"><?php $player=$repPlayer->map($repPlayer->readPlayer($players2[1])); echo $player->fname." ".$player->sname; ?></td>
             <td>
            <?php $winLostMatches=$repCalc->countWonMatches($scheduleID,$player->playerID); 
			echo $winLostMatches['win'];?>
            </td>
            <td><?php echo $winLostMatches['lost']; ?> </td>
          </tr>
          <tr>
            <td class="align-left"><?php $player=$repPlayer->map($repPlayer->readPlayer($players1[2])); echo $player->fname." ".$player->sname; ?></td>
             <td>
            <?php $winLostMatches=$repCalc->countWonMatches($scheduleID,$player->playerID); 
			echo $winLostMatches['win'];?>
            </td>
            <td><?php echo $winLostMatches['lost']; ?> </td>
            
            <td class="align-left"><?php $player=$repPlayer->map($repPlayer->readPlayer($players2[2])); echo $player->fname." ".$player->sname; ?></td>
             <td>
            <?php $winLostMatches=$repCalc->countWonMatches($scheduleID,$player->playerID); 
			echo $winLostMatches['win'];?>
            </td>
            <td><?php echo $winLostMatches['lost']; ?> </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12 no-padding">
            <table class="table table-striped table-bordered align-center">
              <thead>
                <tr>
                  <th><?php echo $team1->team_name;?></th>
                  <th>1</th>
                  <th >2</th>
                  <th >3</th>
                  <th><?php echo $team2->team_name;?></th>
                  <th >1</th>
                  <th >2</th>
                  <th >3</th>
                  <th colspan="2" >Matches</th>
                  <th colspan="2" >Games</th>
                  <th colspan="2" >Points</th>
                </tr>
              </thead>
              <tbody>
                <?php foreach($matches as $m){?>
                
                <tr>
                  <td class="align-left"><?php $player=$repPlayer->map($repPlayer->readPlayer($m->player1ID));
					echo $player->fname." ".$player->sname;?></td>
                  <td><?php if ($repGame->readGame($m->matchID,1)!=""){$game =$repGame->map($repGame->readGame($m->matchID,1));
						echo $game->player1Score;}?></td>
                  <td><?php if ($repGame->readGame($m->matchID,2)!=""){$game =$repGame->map($repGame->readGame($m->matchID,2));
						echo $game->player1Score;}?></td>
                  <td><?php if ($repGame->readGame($m->matchID,3)!=""){
				  $game =$repGame->map($repGame->readGame($m->matchID,3));
						echo $game->player1Score;}?></td>
                  <td class="align-left"><?php  $player=$repPlayer->map($repPlayer->readPlayer($m->player2ID));
					echo $player->fname." ".$player->sname;?></td>
                  <td><?php if ($repGame->readGame($m->matchID,1)!=""){$game =$repGame->map($repGame->readGame($m->matchID,1));
						echo $game->player2Score;}?></td>
                  <td><?php if ($repGame->readGame($m->matchID,2)!=""){$game =$repGame->map($repGame->readGame($m->matchID,2));
						echo $game->player2Score;}?></td>
                  <td><?php  if ($repGame->readGame($m->matchID,3)!=""){$game =$repGame->map($repGame->readGame($m->matchID,3));
						echo $game->player2Score;}?></td>
                  <td>
                  <?php $playersMatch=$repCalc->wonMatch($m->matchID); 
				  echo $playersMatch['player1Match']; ?>
                  </td>
                  <td><?php  echo $playersMatch['player2Match']; ?></td>
                  <td>
                  <?php 
				  $playersGames=$repCalc->wonGamesByMatch($m->matchID); 
				  echo $playersGames['player1Games']; ?>
                  </td>
                  <td><?php echo $playersGames['player2Games']; ?></td>
                  <td>
				  <?php $playersTotalScore=$repCalc->calcPlayerScore($m->matchID); 
				  echo $playersTotalScore['player1TotalScore']; ?>
                  </td>
                  <td><?php echo $playersTotalScore['player2TotalScore']; ?></td>
                </tr>
                <?php  }?>
                <tr>
                <td class="align-left">Doubles 1</td>
                <?php for ($i=0;$i<3;$i++){?>
                <td> <?php echo $doubles[$i]->team1Points; ?></td>
                <?php }?>
                <td class="align-left">Doubles 1</td>
                <?php for ($i=0;$i<3;$i++){?>
                <td> <?php echo $doubles[$i]->team2Points; ?></td>
                <?php }	?>
                <td rowspan="2" class="align-middle">
                	<?php echo $doublesMatches['team1WonDoubles']; ?>
                </td>
                <td rowspan="2" class="align-middle">
                	<?php echo $doublesMatches['team2WonDoubles']; ?>
                </td>
                <td rowspan="2" class="align-middle">
                	<?php echo $gamesDoubles['team1GamesWon_doubles'];?>
                </td>
                <td rowspan="2" class="align-middle">
                	<?php echo $gamesDoubles['team2GamesWon_doubles']; ?>
                </td>
                <td rowspan="2" class="align-middle">
                	<?php echo $pointsDoubles[0];?>
                </td>
                <td rowspan="2" class="align-middle">
                	<?php echo $pointsDoubles[1]; ?>
                </td>
                </tr>
                <tr>
                <td class="align-left">Doubles 2</td>
                <?php for ($i=3;$i<6;$i++){?>
                <td> <?php echo $doubles[$i]->team1Points; ?></td>
                <?php }?>
                <td class="align-left">Doubles 2</td>
                <?php for ($i=3;$i<6;$i++){?>
                <td> <?php echo $doubles[$i]->team2Points; ?></td>
                <?php }?>
                </tr>
                
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
          <?php	ob_flush();?>
</body>
</html>
